log using reg_pop, replace

*Generarates Upper pane of Table 1 and Table1 and all of Table W10
reghdfe nom_rel worker_lim     , abs(m_y) cluster(p_id)
outreg2 using Tables_1pop_W9_W10, replace dec(3) excel  ctitle(slang)
preserve 
keep if valar>1980 & worker_lim!=.
foreach var in nom vald listleader nom_ri vald_ri{
	reghdfe `var'_rel worker_lim     , abs(m_y) cluster(p_id)
	outreg2 using Tables_1pop_W9, append dec(3) excel  ctitle(0 `var'_pop)
	reghdfe `var'_rel worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd    , abs(m_y) cluster(p_id)
	outreg2 using Tables_1pop_W9, append dec(3) excel  ctitle(1 `var'_pop)
	reghdfe `var'_rel worker_lim  std_inc_res  stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y) cluster(p_id)
	outreg2 using Tables_1pop_W9, append dec(3) excel  ctitle( 3 `var'_pop)
	reghdfe `var'_rel worker_lim  stud age_b30- age_ab64 woman non_nordic non_oecd   if   betyg_sd!=.  , abs(m_y) cluster(p_id)
	outreg2 using Tables_1pop_W9, append dec(3) excel  ctitle (4 `var'_pop)
	reghdfe `var'_rel worker_lim std_inc_res betyg_sd stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y) cluster(p_id)
	outreg2 using Tables_1pop_W9 , append dec(3) excel  ctitle( 5 `var'_pop)
	reghdfe `var'_rel worker_lim  stud age_b30- age_ab64 woman non_nordic non_oecd   if   cognitive!=.  , abs(m_y) cluster(p_id)
outreg2 using Tables_1pop_W9, append dec(3) excel  ctitle(6 `var'_pop)
	reghdfe `var'_rel worker_lim std_inc_res cognitive  stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y) cluster(p_id)
	outreg2 using Tables_1pop_W9 , append dec(3) excel   ctitle(7 `var'_pop)
}
restore
preserve 
keep if year>2000

reghdfe nom_left_rel worker_lim_noun  worker_lim_un    std_inc_res stud age_b30-  age_ab64 woman non_nordic non_oecd   , abs(m_y)
outreg2 using Table_2pop , append dec(3) excel  ctitle(Left)
reghdfe  nom_notleft_rel worker_lim_noun  worker_lim_un    std_inc_res stud age_b30-  age_ab64 woman non_nordic non_oecd   , abs(m_y)
outreg2 using Table_2pop , append dec(3) excel  ctitle(Right)

restore


areg nom_rel worker_lim  stud age_b30- age_ab64 woman non_nordic non_oecd   if   std_flex!=.  , abs(m_y)
outreg2 using Tables_W8pop, replace dec(3) excel  ctitle(1 nom_pop)
areg nom_rel worker_lim std_flex stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y)
outreg2 using Tables_W8pop , append dec(3) excel  ctitle(2 nom_pop)	

reghdfe nom_rel worker_isco     , abs(m_y) cluster(p_id)
outreg2 using Tables_W12pop, replace dec(3) excel  ctitle(0 `var'_pop)
reghdfe nom_rel worker_isco stud age_b30- age_ab64 woman non_nordic non_oecd    , abs(m_y) cluster(p_id)
outreg2 using Tables_W12pop, append dec(3) excel  ctitle(1 `var'_pop)
reghdfe nom_rel worker_isco  std_inc_res  stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y) cluster(p_id)
outreg2 using Tables_W12pop, append dec(3) excel  ctitle( 3 `var'_pop)
reghdfe nom_rel worker_isco  stud age_b30- age_ab64 woman non_nordic non_oecd   if   betyg_sd!=.  , abs(m_y) cluster(p_id)
outreg2 using Tables_W12pop, append dec(3) excel  ctitle(4 `var'_pop)
reghdfe nom_rel worker_isco std_inc_res betyg_sd stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y) cluster(p_id)
outreg2 using Tables_W12pop , append dec(3) excel  ctitle( 5 `var'_pop)
reghdfe nom_rel worker_isco  stud age_b30- age_ab64 woman non_nordic non_oecd   if   cognitive!=.  , abs(m_y) cluster(p_id)
outreg2 using Tables_W12pop, append dec(3) excel  ctitle(6 `var'_pop)
reghdfe nom_rel worker_isco std_inc_res cognitive  stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y) cluster(p_id)
outreg2 using Tables_W12pop , append dec(3) excel   ctitle(7 `var'_pop)

preserve 
keep if valar>1980 & worker_lim!=.  & ed_level!=. 
reghdfe nom_rel worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd    , abs(m_y) cluster(p_id)
outreg2 using Tables_W13pop, replace dec(3) excel  ctitle(1 nom_pop)
reghdfe nom_rel worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd    , abs(m_y ed_level) cluster(p_id)
outreg2 using Tables_W13pop,append dec(3) excel  ctitle(2 nom_pop)
reghdfe nom_rel worker_lim stud age_b30- age_ab64 woman non_nordic non_oecd if  ed_level<5  , abs(m_y) cluster(p_id)
outreg2 using Tables_W13pop,append dec(3) excel  ctitle(3 nom_pop)
restore



areg nom_rel worker_lim  stud age_b30- age_ab64 woman non_nordic non_oecd   if   allrelatedtasks!=.  , abs(m_y)
outreg2 using Tables_W14pop, replace dec(3) excel  ctitle(1 nom_pop)
areg nom_rel worker_lim allrelatedtasks stud age_b30- age_ab64 woman non_nordic non_oecd   , abs(m_y)
outreg2 using Tables_W14pop, append dec(3) excel  ctitle(2 nom_pop)	


preserve
keep if valar>2000
gen desc_union="pop"
replace desc_union="rep" if union_worker_prev==1
replace desc_union="emp" if union_worker_mainjob_prev==1
gen non_uni=ed_level<5 & ed_level!=.
collapse (mean) worker_lim non_uni stud age_b30- age_ab64 woman non_nordic non_oecd , by(desc_union)
save Table_W15, replace
restore
preserve
keep if valar>2000
gen desc_union="memb" if worker_union_latest ==1
replace desc_union="nonmemb" if worker_union_latest ==0
gen non_uni=ed_level<5 & ed_level!=.
collapse (mean) worker_lim non_uni stud age_b30- age_ab64 woman non_nordic non_oecd , by(desc_union)
append using Table_W15
save Table_W15, replace
restore
log close
